package com.simba.server.commands.impl.web;

import com.simba.common.command.ICommand;
import com.simba.server.components.SorterParams;
import com.simba.server.components.data.ResultInfo;
import org.apache.log4j.Logger;
import com.simba.common.log.LogUtil;
import com.simba.server.ServerParam;
import com.simba.server.webservice.WebServiceManager;

public class WebOBRStateCmd implements ICommand
{
	public static final String NAME = "WebOBRStateCmd";
	private static final Logger logger = Logger.getLogger(WebOBRStateCmd.class);
	private String status;

	public WebOBRStateCmd(String status)
	{
		this.status = status;
	}

	@Override
	public String getName()
	{
		return WebOBRStateCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;
		String remoteMethod = "getOBRZT";

		String content = "";
		try
		{
			if (SorterParams.getInstance().isDebugMode()){
				LogUtil.LogError(logger, "upload OBR state error: debug mode doesn't upload data!");
				return false;
			}

			ResultInfo response = WebServiceManager.getInstance().doNothing(
					ServerParam.REMOTE_WEBSERVICE_ADDRESS, remoteMethod, content);
			if (response != null)
			{
				ret = this.handleResponse(response);
			}
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebOBRStateCmd.logger, "upload OBR state error: " + e);
			ret = false;

		}
		return ret;
	}

	private boolean handleResponse(ResultInfo response)
	{
		boolean ret = false;
		try
		{
			ret = true;
		}
		catch (Exception e)
		{
			LogUtil.LogError(WebOBRStateCmd.logger, "parse obr status result failed : " + e);
		}
		return ret;
	}
}
